package com.bl.weilan.api.controller.train;

import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.TeacherTrainEntity;
import com.bl.weilan.dao.model.TrainEntity;
import com.bl.weilan.service.biz.train.TrainService;
import com.bl.weilan.service.vo.train.TrainListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/train"})
@Api(value = "培训相关api", description = "培训相关api")
public class TrainController extends BaseController {
    @Autowired
    TrainService trainService;

    @ApiOperation(value = "获取培训列表信息", notes = "获取培训列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_train_list"})
    public ApiResponseBody<TrainListVo> trainList(
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        TrainListVo trainListVo = trainService.getTrainLists(pageable, getUserInfo(request));

        return ApiResponseBody.createSuccessBody(trainListVo);
    }

    @ApiOperation(value = "获取培训列表信息", notes = "获取培训列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_login"})
    public ApiResponseBody<TrainListVo> trainListLogin(
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        TrainListVo trainListVo = trainService.getTrainLists(pageable, getUserInfo(request));

        return ApiResponseBody.createSuccessBody(trainListVo);
    }

    @ApiOperation(value = "获取一条培训详情信息", notes = "获取一条培训")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_train_byid"})
    public ApiResponseBody<TrainListVo> trainList(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        TrainEntity trainEntity = trainService.getTrainById(id);

        return ApiResponseBody.createSuccessBody(trainEntity);
    }

    @ApiOperation(value = "获取一条专家培训详情信息", notes = "获取一条专家培训")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_teacher"})
    public ApiResponseBody<TeacherTrainEntity> teacherTrainList(
            HttpServletRequest request) {

        TeacherTrainEntity trainEntity = trainService.getTeacherTrain();

        return ApiResponseBody.createSuccessBody(trainEntity);
    }

}
